package jdbc10_18;

import java.sql.*;

public class Test_5 {
    public static void main(String[] args) {
        try {
            Class<?> aClass = Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        String url="jdbc:mysql://localhost:3306/jv75";
        Connection root=null;
        PreparedStatement prs=null;
        try {
        root = DriverManager.getConnection(url, "root", "123456");
        String sql="show tables";
            prs = root.prepareStatement(sql);
            ResultSet rs = prs.executeQuery();
            System.out.println("表");
            while (rs.next()){
                String table = rs.getString(1);
                System.out.println(table);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            if (prs!=null) {
                try {
                    prs.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                if (root!=null) {
                    try {
                        root.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
